home *** CD-ROM | disk | FTP | other *** search
/ Cream of the Crop 20 / Cream of the Crop 20 (Terry Blount) (1996).iso / program / vol15n11.zip / HKD.ZIP / HKDSRC.ZIP / HKDDLG.CPP < prev    next >
C/C++ Source or Header  |  1996-04-01  |  42KB  |  1,257 lines

  1. // HKDdlg.cpp : implementation file
  2.  
  3. // HotKey Detective version 1.0
  4. // Copyright (c) 1996 Ziff-Davis Publishing
  5. // First published in PC Magazine June 11, 1996
  6. // Author: Gregory A. Wolking
  7.  
  8. #include "stdafx.h"
  9. #include "HKD.h"
  10. #include "HKDdlg.h"
  11. #include "HKDpDlg.h"
  12.  
  13. #ifdef _DEBUG
  14. #undef THIS_FILE
  15. static char BASED_CODE THIS_FILE[] = __FILE__;
  16. #endif
  17.  
  18. /////////////////////////////////////////////////////////////////////////////
  19. // CAboutDlg dialog used for App About
  20. class CAboutDlg : public CDialog
  21. {
  22. public:
  23.     CAboutDlg();
  24.  
  25. // Dialog Data
  26.     //{{AFX_DATA(CAboutDlg)
  27.     enum { IDD = IDD_ABOUTBOX };
  28.     //}}AFX_DATA
  29.  
  30. // Implementation
  31. protected:
  32.     virtual void DoDataExchange(CDataExchange* pDX);    // DDX/DDV support
  33.     //{{AFX_MSG(CAboutDlg)
  34.     virtual BOOL OnInitDialog();
  35.     //}}AFX_MSG
  36.     DECLARE_MESSAGE_MAP()
  37. };
  38.  
  39. CAboutDlg::CAboutDlg() : CDialog(CAboutDlg::IDD)
  40. {
  41.     //{{AFX_DATA_INIT(CAboutDlg)
  42.     //}}AFX_DATA_INIT
  43. }
  44.  
  45. void CAboutDlg::DoDataExchange(CDataExchange* pDX)
  46. {
  47.     CDialog::DoDataExchange(pDX);
  48.     //{{AFX_DATA_MAP(CAboutDlg)
  49.     //}}AFX_DATA_MAP
  50. }
  51.  
  52. BEGIN_MESSAGE_MAP(CAboutDlg, CDialog)
  53.     //{{AFX_MSG_MAP(CAboutDlg)
  54.         // No message handlers
  55.     //}}AFX_MSG_MAP
  56. END_MESSAGE_MAP()
  57.  
  58. /////////////////////////////////////////////////////////////////////////////
  59. // CAboutDlg message handlers
  60.  
  61. BOOL CAboutDlg::OnInitDialog()
  62. {
  63.     CDialog::OnInitDialog();
  64.     // If main window is minimized, center the about box on the screen,
  65.     // otherwise center it over the main window. All other code for the
  66.     // CAboutDlg class was generated by the App Wizard.
  67.     CenterWindow(GetOwner()->IsIconic() ? GetDesktopWindow() : NULL);
  68.     return TRUE;  // return TRUE  unless you set the focus to a control
  69. }
  70.  
  71. /////////////////////////////////////////////////////////////////////////////
  72. // CHKDDlg dialog
  73. CHKDDlg::CHKDDlg(CWnd* pParent /*=NULL*/)
  74.     : CDialog(CHKDDlg::IDD, pParent)
  75. {
  76.     //{{AFX_DATA_INIT(CHKDDlg)
  77.     //}}AFX_DATA_INIT
  78.     // Note that LoadIcon does not require a subsequent DestroyIcon in Win32
  79.     m_hIcon = AfxGetApp()->LoadIcon(IDR_MAINFRAME);
  80. }
  81.  
  82. void CHKDDlg::DoDataExchange(CDataExchange* pDX)
  83. {
  84.     CDialog::DoDataExchange(pDX);
  85.     //{{AFX_DATA_MAP(CHKDDlg)
  86.     DDX_Control(pDX, cmdPrint, m_cmdPrint);
  87.     DDX_Control(pDX, lblShortcut, m_lblShortcut);
  88.     DDX_Control(pDX, lblFilename, m_lblFilename);
  89.     DDX_Control(pDX, lblWarning, m_lblWarning);
  90.     DDX_Control(pDX, cmdRefresh, m_cmdRefresh);
  91.     DDX_Control(pDX, chkAutoScan, m_chkAutoScan);
  92.     DDX_Control(pDX, cmdExplore, m_cmdExplore);
  93.     DDX_Control(pDX, lstKeys, m_lstKeys);
  94.     DDX_Control(pDX, lstFiles, m_lstFiles);
  95.     //}}AFX_DATA_MAP
  96. }
  97.  
  98. BEGIN_MESSAGE_MAP(CHKDDlg, CDialog)
  99.     //{{AFX_MSG_MAP(CHKDDlg)
  100.     ON_WM_PAINT()
  101.     ON_WM_QUERYDRAGICON()
  102.     ON_WM_SYSCOMMAND()
  103.     ON_BN_CLICKED(cmdRefresh, OncmdRefresh)
  104.     ON_LBN_SELCHANGE(lstKeys, OnSelchangelstKeys)
  105.     ON_LBN_DBLCLK(lstKeys, OnDblclklstKeys)
  106.     ON_BN_CLICKED(cmdExplore, OncmdExplore)
  107.     ON_BN_CLICKED(chkAutoScan, OnchkAutoScan)
  108.     ON_WM_SIZE()
  109.     ON_WM_GETMINMAXINFO()
  110.     ON_WM_CLOSE()
  111.     ON_BN_CLICKED(cmdPrint, OncmdPrint)
  112.     //}}AFX_MSG_MAP
  113. END_MESSAGE_MAP()
  114.  
  115. /////////////////////////////////////////////////////////////////////////////
  116. // CHKDDlg message handlers
  117. BOOL CHKDDlg::OnInitDialog()
  118. {
  119.     RECT r;
  120.  
  121.     // Wizard-Generated code.
  122.     CDialog::OnInitDialog();
  123.     CenterWindow();
  124.     // Add "About..." menu item to system menu.
  125.     // IDM_ABOUTBOX must be in the system command range.
  126.     ASSERT((IDM_ABOUTBOX & 0xFFF0) == IDM_ABOUTBOX);
  127.     ASSERT(IDM_ABOUTBOX < 0xF000);
  128.     CMenu* pSysMenu = GetSystemMenu(FALSE);
  129.     CString strAboutMenu;
  130.     strAboutMenu.LoadString(IDS_ABOUTBOX);
  131.     if (!strAboutMenu.IsEmpty())
  132.     {
  133.         pSysMenu->AppendMenu(MF_SEPARATOR);
  134.         pSysMenu->AppendMenu(MF_STRING, IDM_ABOUTBOX, strAboutMenu);
  135.     }
  136.  
  137.     // Custom code
  138.     // Load our small and large icons.
  139.     SendMessage(WM_SETICON,(WPARAM)(BOOL)TRUE,(LPARAM)m_hIcon);
  140.     SendMessage(WM_SETICON,(WPARAM)(BOOL)FALSE,(LPARAM)m_hIcon);
  141.     // Set minimum tracking size for use by OnGetMinMaxInfo()
  142.     GetWindowRect(&r);
  143.     min_track_x = r.right - r.left;
  144.     min_track_y = r.bottom - r.top;
  145.     // Unless we're starting minimized, adjust control positions relative
  146.     // to the dialog borders.
  147.     if (!IsIconic())
  148.         Adjust_Controls();
  149.     // Initialize pointer for our worker thread.
  150.     my_thread = NULL;
  151.     // Get paths to the Start Menu and Desktop Folders.
  152.     if (!Get_Folder_Paths())
  153.     {
  154.         // If call fails, report error and quit.
  155.         Do_Error_Message("Could not read Explorer's folder\nsettings from the Registry.");
  156.         EndDialog(IDOK);
  157.     }
  158.     else
  159.     {
  160.         // Create dlg_Scanning screen window (initially hidden).
  161.         dlg_Scanning.Create(IDD_SPLASH, this);
  162.         // Read option settings from the Registry.
  163.         if (!Read_My_Settings())
  164.         {
  165.             // If read fails, set default and save it.
  166.             m_chkAutoScan.SetCheck(1);
  167.             Save_My_Settings();
  168.         }
  169.         // If Automatic Refresh is enabled,
  170.         if (m_chkAutoScan.GetCheck())
  171.             // start our worker thread, which automatically triggers a refresh.
  172.             Launch_Worker();
  173.         else
  174.             // Otherwise, refresh manually.
  175.             OncmdRefresh();
  176.     }
  177.     return TRUE;  // return TRUE unless you set the focus to a control
  178. }
  179.  
  180. // WM_GETMINMAXINFO handler
  181. // Sets minimum dimensions when window is resized.
  182. void CHKDDlg::OnGetMinMaxInfo(MINMAXINFO FAR* lpMMI)
  183. {
  184.     // If dialog doesn't exist yet, controls won't exist either.
  185.     // We don't want to set this metric until the dialog has been
  186.     // created and OnInitDialog() has set the desired size.
  187.     if (m_lblShortcut)
  188.     {
  189.         lpMMI->ptMinTrackSize.x = min_track_x;
  190.         lpMMI->ptMinTrackSize.y = min_track_y;
  191.     }
  192. }
  193.  
  194. // System menu handler (more Wizard code)
  195. void CHKDDlg::OnSysCommand(UINT nID, LPARAM lParam)
  196. {
  197.     if ((nID & 0xFFF0) == IDM_ABOUTBOX)
  198.     {
  199.         CAboutDlg dlgAbout;
  200.         dlgAbout.DoModal();
  201.     }
  202.     else
  203.         CDialog::OnSysCommand(nID, lParam);
  204. }
  205.  
  206. // OnCancel is always called last when user exits. Since the user can exit this
  207. // dialog by either clicking the close box or pressing {Esc}, we want to make sure
  208. // that the necessary shutdown work is done regardless of the method used.
  209. // Since there is no special processing required when the Close box is used,
  210. // the CDialog::OnClose() member function is not overriden in this implementation.
  211. void CHKDDlg::OnCancel()
  212. {
  213.     // Make sure worker thread is shut down.
  214.     Kill_Worker();
  215.     // Save auto-refresh setting.
  216.     Save_My_Settings();
  217.     // Destroy the splash screen.
  218.     dlg_Scanning.DestroyWindow();
  219.     // Call base class to finish up and end the application.
  220.     CDialog::OnCancel();
  221. }
  222.  
  223. // Handles drawing the icon if window is minimized.
  224. // This function and OnQueryDragIcon() are both App Wizard code.
  225. void CHKDDlg::OnPaint()
  226. {
  227.     if (IsIconic())
  228.     {
  229.         CPaintDC dc(this); // device context for painting
  230.         SendMessage(WM_ICONERASEBKGND, (WPARAM) dc.GetSafeHdc(), 0);
  231.  
  232.         // Center icon in client rectangle
  233.         int cxIcon = GetSystemMetrics(SM_CXICON);
  234.         int cyIcon = GetSystemMetrics(SM_CYICON);
  235.         CRect rect;
  236.         GetClientRect(&rect);
  237.         int x = (rect.Width() - cxIcon + 1) / 2;
  238.         int y = (rect.Height() - cyIcon + 1) / 2;
  239.  
  240.         // Draw the icon
  241.         dc.DrawIcon(x, y, m_hIcon);
  242.     }
  243.     else
  244.         CDialog::OnPaint();
  245. }
  246.  
  247. // The system calls this to obtain the cursor to display while the user drags
  248. // the minimized window.
  249. HCURSOR CHKDDlg::OnQueryDragIcon()
  250. {
  251.     return (HCURSOR) m_hIcon;
  252. }
  253.  
  254. // The remainder of this file is custom code.
  255. /////////////////////////////////
  256. // Rearrange controls when dialog is resized
  257. /////////////////////////////////
  258. void CHKDDlg::OnSize(UINT nType, int cx, int cy)
  259. {
  260.     // If the controls exist (On_Size is called once before the controls are drawn),
  261.     if (m_lblShortcut)
  262.         // and we're not being minimized,
  263.         if (nType != SIZE_MINIMIZED)
  264.             // adjust their positions.
  265.             Adjust_Controls();
  266. }
  267.  
  268. /////////////////////////////
  269. // Command button handlers //
  270. /////////////////////////////
  271.  
  272. ///////////////////////////
  273. // Refresh Key List button.
  274. // Also called by OnInitDialog() and our worker thread.
  275. ///////////////////////////
  276. void CHKDDlg::OncmdRefresh()
  277. {
  278.     // Disable button so the user can't stack up refresh requests.
  279.     m_cmdRefresh.EnableWindow(FALSE);
  280.     // If we'r